<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备">
              <j-search-select-tag
                v-model="queryParam.deviceId"
                dict="ene_device,device_name,id"
                placeholder="请选择设备"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button type='primary' icon='download' @click="handleExportXls('报废审批')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap1"
        @change="handleTableChange">

        <template slot="scrapNo" slot-scope="text,record">
          <a v-html="text" @click="handleDetailDrawer(record)"></a>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <span v-if="record.status==2" style="color: green">{{ text }}</span>
          <span v-else-if="record.status==3" style="color: red">{{ text }}</span>
          <span v-else-if="record.status==1" style="color: blue">{{ text }}</span>
          <span v-else>{{ text }}</span>
        </span>
        <span slot="action" slot-scope="text, record">
        <a @click="submitApplication(record)">审批</a>
        </span>

      </a-table>
    </div>

    <ene-device-approval-modal ref="modalForm" @ok="modalFormOk"></ene-device-approval-modal>

    <TabsDrawer :width="1400" ref="tabsDrawer">
      <template slot="tabs-0">
        <collapse-comp @initData="initData" ref="collapsRef"></collapse-comp>
      </template>
    </TabsDrawer>
  </a-card>
</template>

<script>

import '@assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import EneDeviceApprovalModal from "@views/business/device/modules/EneDeviceApprovalModal.vue";
import CollapseComp from "@comp/Collapse/CollapsComp.vue";
import TabsDrawer from '@/components/Drawer/TabsDrawer'

export default {
  name: 'EneDeviceApprovalList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    TabsDrawer,
    CollapseComp,
    EneDeviceApprovalModal
  },
  data() {
    return {
      description: '设备报废管理页面',
      // 表头
      columns: [
        {
          title: '报废单号',
          align: "center",
          dataIndex: 'scrapNo',
          scopedSlots: {customRender: 'scrapNo'},
        },
        {
          title: '设备名称',
          align: "center",
          dataIndex: 'deviceId_dictText'
        },
        {
          title: '创建人',
          align: "center",
          dataIndex: 'createBy_dictText'
        },
        {
          title: '报废原因',
          align: "center",
          dataIndex: 'scrapReason'
        },
        {
          title: '提报时间',
          align: "center",
          dataIndex: 'subTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/test/EneDeviceScrap/approvalList",
        submit: "/test/EneDeviceScrap/submit",
        exportXlsUrl: '/test/EneDeviceScrap/exportApprovalXls',
        importExcelUrl: '/test/EneDeviceScrap/importExcel'
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'scrapNo', text: '报废单号', dictCode: ''})
      fieldList.push({
        type: 'string',
        value: 'deviceId',
        text: '设备',
        dictTable: "ene_device",
        dictText: 'device_name',
        dictCode: 'id'
      })
      fieldList.push({type: 'string', value: 'status', text: '状态', dictCode: 'order_status'})
      fieldList.push({type: 'string', value: 'scrapReason', text: '报废原因', dictCode: ''})
      fieldList.push({type: 'string', value: 'createBy', text: '创建人', dictCode: ''})
      fieldList.push({type: 'datetime', value: 'subTime', text: '提报时间'})
      this.superFieldList = fieldList
    },
    submitApplication(record) {
      this.$refs.modalForm.check(record);
      this.$refs.modalForm.title = "设备报废审批";
      this.$refs.modalForm.disableSubmit = false;
    },
    handleDetailDrawer(record) {
      this.$refs.tabsDrawer.record = record;
      this.$refs.tabsDrawer.topData = [
        {
          name: '设备名称', value: record.deviceId_dictText, lg: 3
        },
        {
          name: '报废单号', value: record.scrapNo, lg: 3
        },
        {
          name: '创建人', value: record.createBy_dictText, lg: 3
        },
        {
          name: '报废原因', value: record.scrapReason, lg: 3
        },
      ];
      this.$refs.tabsDrawer.tabsData = [
        {
          title: '基础信息'
        },
      ]
      this.selectedRecord = record

      this.$refs.tabsDrawer.visible = true

    },
    initData() {
      const record = this.selectedRecord
      this.$refs.collapsRef.collapseData = [
        {
          title: '基础信息',
          children: [
            {
              label: '设备名称',
              value: record.deviceId_dictText
            },
            {
              label: '报废单号',
              value: record.scrapNo
            },
            {
              label: '创建人',
              value: record.createBy_dictText
            },
            {
              label: '提报原因',
              value: record.scrapReason
            },
            {
              label: '设备图片',
              value: record.deviceImages
            }
          ]
        },
        {
          title: '审批信息',
          children: [
            {
              label: '审批人',
              value: record.approvlBy_dictText
            },
            {
              label: '审批时间',
              value: record.updateTime
            },
            {
              label: '审批描述',
              value: record.approvDescribe
            },
          ]
        },
        {
          title: '系统信息',
          children: [
            {
              label: '创建人',
              value: record.createBy_dictText
            },
            {
              label: '创建时间',
              value: record.createTime
            },
            {
              label: '修改人',
              value: record.updateBy
            },
            {
              label: '修改时间',
              value: record.updateTime
            },
          ]
        }
      ]
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>